package logic

import (
	"context"
	"errors"
	"shop_srv/model/redisinit"

	"shop_srv/internal/svc"
	"shop_srv/shop"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteCardLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDeleteCardLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteCardLogic {
	return &DeleteCardLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 清除购物车
func (l *DeleteCardLogic) DeleteCard(in *shop.DeleteCardRequest) (*shop.DeleteCardResponse, error) {
	// todo: add your logic here and delete this line

	err := redisinit.DeleteCard(int(in.UserId))
	if err != nil {
		logx.Error("购物车清除失败")
		return nil, errors.New("购物车清除失败")
	}
	return &shop.DeleteCardResponse{}, nil
}
